﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DevExpress.Xpo;
using System.Configuration;
namespace ChuanPlus
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            XpoDefault.DataLayer = XpoDefault.GetDataLayer(GetConnectionString(), DevExpress.Xpo.DB.AutoCreateOption.None);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain());
        }
        private static string GetConnectionString()
        {
            AppSettingsReader config = new AppSettingsReader();
            string serverType, server, database, user, password;
            serverType = ((string)(config.GetValue("ServerType", typeof(string))));
            server = ((string)(config.GetValue("Server", typeof(string))));
            database = ((string)(config.GetValue("Database", typeof(string))));
            user = ((string)(config.GetValue("User", typeof(string))));
            password = ((string)(config.GetValue("Password", typeof(string))));
            switch (serverType)
            {
                case "MSSQL":
                    return DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString(server, user, password, database);
                case "Access":
                    return DevExpress.Xpo.DB.AccessConnectionProvider.GetConnectionString(database, user, password);
                // ... generate connection strings for other providers, e.g. MySql, Firebird, etc.
                case "MySQL":
                    return DevExpress.Xpo.DB.MySqlConnectionProvider.GetConnectionString(server, user, password, database);
                default:
                    return Session.DefaultSession.ConnectionString;
            }
        }
    }
}
